<template>
	<view class="mainbgc">
		<header-top :messageInfo="{typeFlag:true,message:'库存调拨单查询',liner:false}">
			<view class="rightmsg" slot="rightmsg">
				<view class="rightmsg_content flexleft" @click="show=true">筛选</view>
			</view>
		</header-top>
		<view class="mainpadding">
			<view class="flexbetween">
				<input class="input-text" type="text" placeholder="请输入单号" v-model="keywords" confirm-type="search" @confirm="init">
				<view class="sousuo" @click="init()">搜索</view>
			</view>
			<view class="flexcenter" v-if="!list.total">
				<view class="placeholderimage"></view>
			</view>
			<view class="radius radius mainpadding_top ffffff" v-for="item in list.data" :key="item.id"
				@click="jumpdetail(item.id,96)">
				<view class="flexbetween">
					<view class="ywy margin_right">{{item.order_no}}</view>
					<!-- 10=出库待审核,20=已出库,30=已入库,40=出库未通过,50=入库未通过 -->
					<view class="wlable radius" v-if="item.status==10">出库待审核</view>
					<view class="shlable radius" v-if="item.status==20">已出库</view>
					<view class="shlable radius" v-if="item.status==30">已入库</view>
					<view class="hlable radius" v-if="item.status==40">出库未通过</view>
					<view class="hlable radius" v-if="item.status==50">入库未通过</view>
				</view>
				<view class="margin_top drdcbox">
					<view class="flexleft">
						<view class="diaochu margin_right">调出</view>
						<view class="titletext">{{item.warehouseout.name}}</view>
						<view class="namecolor">
							{{item.outstaff.username}}</view>
						<view class="flexright" @click.stop="phone(item.outstaff.mobile)">
							<view class="littleblue"></view>
						</view>
					</view>
					<view class="downimage3"></view>
					<view class="flexleft">
						<view class="diaoru margin_right">调入</view>
						<view class="titletext">{{item.warehousejoin.name}}</view>
						<view class="namecolor">
							{{item.joinstaff.username}}</view>
						<view class="flexright" @click.stop="phone(item.joinstaff.mobile)">
							<view class="littleblue"></view>
						</view>
					</view>
				</view>
				<view class="margin_top ywy">
					<view>经办人：{{item.staff.username}} {{item.staff.mobile}}</view>
				</view>
				<view class="margin_top ywy">
					<view>共{{item.goods_zl_num}}种/{{item.goods_num}}件</view>
				</view>
				<view class="margin_top ywy nostrongtext yihang" v-show="item.notes">备注：{{item.notes}}</view>
				<view class="margin_top ywy flexbetween">
					<view>{{item.createtime_text}}</view>
					<!-- <view>{{item.createtime_text}}</view> -->
					<view class="xiaolankuang flexright margin_left2" v-if="(item.status==10 && item.is_out_user==1) || (item.status==20 && item.is_join_user==1)"
						@click.stop="currentitem=item;examine(item.id,95)">
						<u-icon name="android-fill" color="#0BBDCB" size="16"></u-icon>
						<view class="xiaolan margin_left1">审核</view>
					</view>
				</view>
			</view>
		</view>
		<u-popup round="20" :show="show" @close="show=false">
			<view class="mainpadding">
				<view class="flexcenter">
					<view class="titletext">筛选</view>
				</view>
				<view class="strongtext margin_top">时间</view>
				<view class="flexleft" style="flex-wrap: wrap;">
					<view class="screenbox flexcenter" v-for="(item,index) in datelist" :key="item.id"
						@click="change(item.name,index)">
						<view :class="currents == index? 'itemscreenfocus margin_top':'itemscreen margin_top'">
							{{item.name}}
						</view>
					</view>
				</view>
				<view class="strongtext margin_top">自定义时间</view>
				<view class="flexleft">
					<view class="inputscreenbox flexcenter" @click="shows=true">
						<input class="itemscreen margin_top" type="text" disabled v-model="start">
					</view>
					<view class="zwscreenbox flexcenter">
						<view class="strongtext">-</view>
					</view>
					<view class="inputscreenbox flexcenter" @click="showss=true">
						<input class="itemscreen margin_top" type="text" disabled v-model="end">
					</view>
				</view>
				<view class="strongtext margin_top">状态</view>
				<view class="flexleft" style="flex-wrap: wrap;">
					<view class="screenbox flexcenter" v-for="(item,index) in statuslist" :key="item.id"
						@click="changestatus(item.id)">
						<view :class="currentstatus == item.id?'itemscreenfocus margin_top':'itemscreen margin_top'">
							{{item.name}}
						</view>
					</view>
				</view>
				<view class="flexbetween">
					<view class="surebtn reset flexcenter" style="margin-top: 60rpx;" @click="resetbtn">重置</view>
					<view class="surebtn flexcenter" style="margin-top: 60rpx;" @click="sureBtn">确认</view>
				</view>
			</view>
		</u-popup>
		<u-datetime-picker :show="shows" v-model="value1" mode="date" @confirm="confirm" @cancel="shows=false"
			 @close="shows=false"></u-datetime-picker>
		<u-datetime-picker :show="showss" v-model="value2" mode="date" @confirm="confirms" @cancel="showss=false"
			:minDate="mintime" @close="showss=false"></u-datetime-picker>
		<u-modal :show="examineShow" title="审核" @confirm="examineConfirm" showCancelButton @cancel="examineShow=false">
			<view class="slot-content">
				<view class="mainpadding_top">
					<u-radio-group v-model="examineType" placement="column" circle>
						<!-- 20=已出库,30=已入库,40=出库未通过,50=入库未通过 -->
						<template v-if="currentitem.status==10">
							<u-radio activeColor="#0BBDCB" :customStyle="{marginBottom: '20rpx'}" label="已出库" name="20"></u-radio>
							<u-radio activeColor="#0BBDCB" label="出库未通过" name="40"></u-radio>
						</template>
						<template v-if="currentitem.status==20">
							<u-radio activeColor="#0BBDCB" :customStyle="{marginBottom: '20rpx'}" label="已入库" name="30"></u-radio>
							<u-radio activeColor="#0BBDCB" label="入库未通过" name="50"></u-radio>
						</template>
						
					</u-radio-group>
				</view>
				
			</view>
		</u-modal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				currentitem:{},
				// 时间选择
				datelist: [{
						id: 1,
						name: '今日'
					},
					{
						id: 2,
						name: '昨日'
					},
					{
						id: 3,
						name: '本月'
					},
				],
				// 审核
				// 10=出库待审核,20=已出库,30=已入库,40=出库未通过,50=入库未通过
				statuslist: [{
						id: 10,
						name: '出库待审核'
					},
					{
						id: 20,
						name: '已出库'
					},
					{
						id: 30,
						name: '已入库'
					},
					{
						id: 40,
						name: '出库未通过'
					},
					{
						id: 50,
						name: '入库未通过'
					},
				],
				show: false, //筛选弹出层
				// 时间筛选
				currents: -1,
				currentstatus: -1,
				start: '开始时间',
				end: '结束时间',
				shows: false,
				showss: false,
				value1: Number(new Date()),
				value2: Number(new Date()),
				mintime: Number(new Date()),
				keywords: "",
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				// 审核
				examineType:"20",
				examineShow:false,
				examineId:"",
			}
		},
		onLoad(options) {
			if(options.type){
				this.currentstatus = options.type
			}
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this;
				httpRequest.request('/dhtapi/Dbdorder/index', 'POST', {
					page: page || 1,
					limit: _this.limit,
					keywords: this.keywords,
					start_time:this.start=='开始时间'?'':this.start,//开始日期
					end_time:this.end=='结束时间'?'':this.end,//结束日期
					status:this.currentstatus==-1?'':this.currentstatus,//10=出库待审核,20=已出库,30=已入库,40=出库未通过,50=入库未通过
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							_this.list = resList
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			examine(id,qxpdid) {
				if (!httpRequest.qxpd(qxpdid, this.$store.state.userInfo.ability_rule_ids)) {
					return false
				}
				this.examineId = id
				this.examineShow = true
			},
			examineConfirm(){
				this.examineShow = false
				httpRequest.request('/dhtapi/Dbdorder/applyDbdOrder', 'GET', {
					id: this.examineId,
					status: this.examineType
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.init()
					}
				})
			},
			date(timer) {
				var date = new Date(timer); //当前时间
				var year = date.getFullYear() //返回指定日期的年份
				var month = repair(date.getMonth() + 1); //月
				var day = repair(date.getDate()); //日
				var curTime = year + "-" + month + "-" + day

				function repair(i) {
					if (i >= 0 && i <= 9) {
						return "0" + i;
					} else {
						return i;
					}
				}
				return curTime
			},
			confirm(e) {
				console.log(e);
				this.shows = false;
				this.show = true;
				this.end = '结束时间';
				this.mintime = e.value;
				this.start = this.date(e.value);
				this.currents = -1;
			},
			confirms(e) {
				this.showss = false;
				this.show = true;
				this.end = this.date(e.value);
				this.currents = -1;
			},
			changestatus(index) {
				this.currentstatus = index;
			},
			change(name, index) {
				if (name == "今日") {
					this.start = this.riqi(0);
					this.end = this.riqi(0);
				} else if (name == "昨日") {
					this.start = this.riqi(-1);
					this.end = this.riqi(-1);
				} else if (name == "本月") {
					this.start = this.benyue();
					this.end = this.riqi(0);
				}
				this.currents = index;
			},
			// 昨天“-1”今天“0”明天“1”
			riqi(day) {
				let dd = new Date();
				dd.setDate(dd.getDate() + day);
				let y = dd.getFullYear();
				let m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
				let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
				return y + "-" + m + "-" + d;
			},
			// 本月第一天
			benyue() {
				let y = new Date().getFullYear(); //获取年份
				let m = new Date().getMonth() + 1; //获取月份
				let d = '01'
				m = m < 10 ? '0' + m : m; //月份补 0
				return [y, m, d].join("-")
			},
			// 重置
			resetbtn() {
				this.currentstatus = -1
				this.currents = -1
				this.start = "开始时间"
				this.end = "结束时间"
				this.init()
				this.show = false
			},
			sureBtn() {
				this.show = false
				this.init()
			},
			// 调拨单详情
			jumpdetail(id,qxpdid) {
				if (!httpRequest.qxpd(qxpdid, this.$store.state.userInfo.ability_rule_ids)) {
					return false
				}
				uni.navigateTo({
					url: '/pages/workbench/kucun/kucundbxq?id=' + id
				})
			},
			phone(p) {
				uni.makePhoneCall({
					phoneNumber: p.toString()
				}).catch((e) => {
					// console.log(e)  //用catch(e)来捕获错误{makePhoneCall:fail cancel}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.seletext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		line-height: 28rpx;
	}

	.miancolor {
		color: #0BBDCB;
	}

	.smalltext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.ywy {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	// 审核状态
	.wlable {
		padding: 6rpx 14rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #F3AD3D;
		line-height: 28rpx;
		background-color: #fef7ec;
	}
	.hlable{
		padding: 6rpx 14rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #ff0000;
		line-height: 28rpx;
		background-color: rgba(255, 0, 0, .1);
	}

	.shlable {
		padding: 6rpx 14rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
		line-height: 28rpx;
		background-color: #e7f9fa;
	}

	.inputscreenbox {
		width: 40%;

		input {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			border-radius: 50rpx;
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #333;
			background-color: #f7f9fa;
		}
	}

	.zwscreenbox {
		width: 20%;
		line-height: 80rpx;
	}

	.itemscreenfocus {
		width: 200rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 50rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
		background-color: #e7f9fa;
	}

	// 筛选内容
	.screenbox {
		width: 33.33%;
	}

	.itemscreen {
		width: 200rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 50rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		background-color: #f7f9fa;
	}

	.surebtn {
		width: 45%;
	}

	.reset {
		background: #ebb563;
	}

	.diaochu {
		border: 1rpx solid #0BBDCB;
		border-radius: 5rpx;
		font-size: 20rpx;
		background-color: #fff;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
		padding: 6rpx 14rpx;
	}

	.diaoru {
		border: 1rpx solid #0BBDCB;
		border-radius: 5rpx;
		font-size: 20rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		background-color: #0BBDCB;
		color: #fff;
		padding: 6rpx 14rpx;
	}

	.downimage3 {
		margin: 10rpx 0 10rpx 20rpx;
	}

	.minwidth {
		min-width: 130rpx;
	}

	.rightscreen {
		width: 100%;
	}

	.itemscreens {
		padding-bottom: 20rpx;
	}
</style>